<?php
App::import('Model', 'Comments.CmsComment');
class ReviewComment extends CmsComment
{
	var $name = 'ReviewComment';
	const PUBLISH = 1;
	const UNPUBLISH = 0;
	var $scopes = array(
		'published' => array('ReviewComment.status'=>self::PUBLISH)
	);
	var $belongsTo = array(
					'Review'=>array(
							'className'=>'Review',
							'foreignKey'=>'review_id',
							'counterCache' => true,
							'counterScope' => array('ReviewComment.status'=>self::PUBLISH)
							),
					'User'=>array(
							'className'=>'Users.User',
							'foreignKey'=>'user_id',
							'counterCache' => true,
							'counterScope' => array('ReviewComment.status'=>self::PUBLISH)
							),								
					);
	var $actsAs = array(
			'Cms.Metric'=>array(
							array('metric'=>'NumRecords')
					),
			'Users.UserContent' => array(
				'badwordFilter' => true, 
				'fieldsToFilter' => array('body'),
				'posterModels'=>array('Users.User'=>array('dependent'=>true),'Users.Guest')	
			)
	);	
	
	function getMostCommented()
	{
		$commentInfo = $this->find('all',array('fields'=>array('review_id','count(ReviewComment.id) as count'),'group'=>array('review_id'),'order'=>array('count DESC')));
		$reviewIds = Set::extract($commentInfo,'{n}.ReviewComment.review_id');
		return $reviewIds;
		
	}
	
	function afterInitialize()
	{	
		parent::afterInitialize();	
		$this->setFieldProperties('body',array('class'=>'required'));
	}
}
?>